home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / addr / ghost.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-06-04  |  4.3 KB  |  210 lines

  1. #include "util.h"
  2. #include "mmdf.h"
  3. #include <pwd.h>
  4. #include "ch.h"
  5. #include "dm.h"
  6. #include "ap.h"
  7.  
  8.  
  9. extern struct ll_struct *logptr;
  10. extern char *ch_dflnam;
  11. extern char *blt();
  12. extern char *index();
  13. extern char *rindex();
  14. extern char *locname;
  15. extern char *supportaddr;
  16. extern char *sitesignature;
  17. extern char *locmachine;               /* local machine name           */
  18. extern int mgt_inalias;
  19.  
  20. char *adr_fulldmn;      /* Name of 'full' domain                */
  21.  
  22. char *adr_orgspec;       /* original mailbox string      */
  23.  
  24. LOCVAR char adr_gotone;
  25.  
  26. char *adr_ghost ();
  27.  
  28.  
  29.  
  30. main ()
  31.  
  32.  
  33. {
  34.  
  35.     char instr[1000];
  36.     char thename[1000];
  37.     char * result;
  38.     char tstline[1000];
  39.     char newloc[1000];
  40.  
  41.     mmdf_init ("GHOST");
  42.  
  43.     logptr -> ll_level = LLOGFTR ;
  44.  
  45.     printf ("Locname '%s', Locmachine '%s'\n\n", locname, locmachine);
  46.  
  47.  
  48.     while (1)
  49.  
  50.     {
  51.  
  52.         printf ("Enter the string to parse: "); 
  53.         fflush(stdout);
  54.         scanf ("%s", instr);
  55.  
  56.         while (1)
  57.         {
  58.             result = adr_ghost(instr, (short) strlen(instr), thename);
  59.  
  60.             if (result ==  (char *) NOTOK )
  61.             {
  62.                 printf ("Error returned by 'adr_ghost' for '%s'", instr);
  63.                 fflush(stdout);
  64.                 goto done;
  65.             }
  66.             else
  67.             {
  68.                 printf ("Host is '%s'     ", thename); 
  69.                 fflush(stdout);
  70.                 printf ("Pointer at '%s'\n", result); 
  71.                 fflush (stdout);
  72.  
  73.                 if (lexequ(thename, locmachine)) 
  74.                 {
  75.                     printf ("Let's try again \n") ;
  76.                     fflush (stdout);
  77.                     continue ;  
  78.                 }
  79.     /* keep going until we're out of names or we find one */
  80.  
  81.                 /*  Now, we should have a host left now.  Let's see if it exists */
  82.  
  83.                 if (dm_h2domain (thename, tstline) == (Domain *) NOTOK)
  84.                 {
  85.                     printf ("Lossage trying to get '%s' in the tables\n", thename); fflush(stdout);
  86.                     goto done;
  87.                 }
  88.                 else
  89.                 {
  90.                     *result = '\0';        /* terminate the new "local" part */
  91.                     printf ("Local is '%s' and Domain is '%s'\n", instr, tstline); fflush(stdout);
  92.                 }
  93.  
  94.             }
  95.         }  /* end WHILE (1)  */
  96.     }
  97.  
  98. done:  
  99.     printf ("Bye\n"); fflush(stdout);
  100. }
  101.  
  102. /* */
  103.  
  104. char *
  105. adr_ghost (buf, len, to)  /* get host field from end of text    */
  106. char   *buf;                      /* the buffer holding the text        */
  107. short     len;                      /* length of the buffer               */
  108. char   *to;                       /* put "hostname" into here           */
  109. {
  110.     extern char *compress ();
  111.     register char  *strptr;
  112.     int    hostlen;
  113.     char   *hostptr;
  114.     char   *endptr;
  115.  
  116. #ifdef DEBUG
  117.     ll_log (logptr, LLOGFTR, "adr_ghost (%s)", buf);
  118. #endif
  119.     for (strptr = &(buf[len - 1]); isspace (*strptr); strptr--);
  120.     /* skip trailing white space          */
  121.     for (hostptr = endptr = strptr;; hostptr = strptr--)
  122.     {
  123.         if (strptr <= buf)
  124.             return ((char *) NOTOK);       /* reached beginning of string */
  125.         switch (*strptr)
  126.         {
  127.         case '>':             /* a "foo bar <adr @ host>" spec */
  128.             *strptr = '\0';
  129.             for (strptr = buf; ; strptr++)
  130.                 switch (*strptr)
  131.                 {
  132.                 case '\0':
  133.                     return ((char *) NOTOK);
  134.  
  135.                 case '<':
  136.                     compress (++strptr, buf);
  137.                     return (adr_ghost (buf, strlen (buf), to));
  138.                 }
  139.  
  140.         case ')':             /* trailing comment field             */
  141.         {
  142.             short pcount = 1;
  143.  
  144.             while (--strptr > buf && pcount)
  145.             {
  146.                 if (*strptr == '(') pcount--;
  147.                 if (*strptr == ')') pcount++;
  148.                 if (pcount == 0)
  149.                 {
  150.                     while (strptr > buf &&
  151.                            isspace (*--strptr));
  152.                     *++strptr = '\0';
  153.                     break;
  154.                 }
  155.             }
  156.         }
  157.             continue;
  158.  
  159.         default:
  160.             continue;
  161.  
  162.         case '@':
  163.         case '%':             /* same as @ */
  164.         case '.':             /* same as @ */
  165.             break;
  166.  
  167.         case ' ':
  168.         case '\t':
  169.             for (strptr--; (strptr > buf) && isspace (*strptr);
  170.             strptr--);
  171.                 switch (*strptr)  /* got one now                        */
  172.             {
  173.             case '@':
  174.             case '%':
  175.             case '.':
  176.                 break;
  177.  
  178.             default:      /* " at "??                           */
  179.                 if (equal (&strptr[-1], "AT", 2))
  180.                     strptr--;
  181.                 else      /* tsk tsk                            */
  182.                 return ((char *) NOTOK);
  183.             }
  184.             break;
  185.         }
  186.         break;
  187.     }
  188.     if (to)
  189.     {
  190.         hostlen = endptr - hostptr;
  191.         if (hostlen == 0)
  192.             (void) strcpy (to, locname);
  193.         else
  194.         {
  195.             *(blt (hostptr, to, hostlen + 1)) = '\0';
  196.             compress (to, to);
  197.             if (strlen (to) == 0)       /* null host field */
  198.             {
  199.             /* default to local host */
  200.             (void) strcpy (to, locname);
  201.             }
  202.         }
  203.     }
  204.     while (isspace (*--strptr));
  205.     strptr++;                     /* leave pointer just AFTER graphics  */
  206.     return (strptr);
  207. }
  208. /* */
  209.  
  210.